package org.sq;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.location.Location;
import android.location.LocationManager;

public class Quest implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String levelName;

	public String getLevelName() {
		return levelName;
	}

	public void setLevelName(String levelName) {
		this.levelName = levelName;
	}

	private ArrayList<String> answers;
	private String answerTime;
	private String userReply = "";
	private ArrayList<String> levelKeys;
	
	transient Location _location;
	private Double lng = 0.d;
	private Double lat = 0.d;
	private boolean completed;
	private int compTime;
	private int points = 0;
	private String title;

	public boolean isCompleted() {
		return completed;
	}

	public void setCompleted(boolean completed) {
		this.completed = completed;
	}

	public void addAnswerVariant(String answer) {
		if (answers == null) {
			answers = new ArrayList<String>();
		}
		answers.add(answer);
	}

	public boolean checkAnswer(String answer) {
		if (answers != null) {
			for (String s : answers) {
				if (s.equalsIgnoreCase(answer)) {
					return true;
				}
			}
		}
		return false;
	}

	// public String getAnswer() {
	// return _answer;
	// }
	//
	// public void setAnswer(String _answer) {
	// this._answer = _answer;
	// }

	public Location getLocation() {
		if(_location == null){
			_location = new Location(LocationManager.GPS_PROVIDER);
		}
		_location.setLatitude(lat);
		_location.setLongitude(lng);
		return _location;
	}

	public void setLocation(Location _location) {
		this._location = _location;
	}

	public boolean hasKeys() {
		if (this.levelKeys == null) {
			return false;
		}
		if (this.levelKeys.size() == 0) {
			return false;
		}
		return true;
	}

	public int getCompTime() {
		return compTime;
	}

	public void setCompTime(int compTime) {
		this.compTime = compTime;
	}

	public int getPoints() {
		return points;
	}

	public void setPoints(int pints) {
		this.points = pints;
	}

	public String getTitle() {

		String titleStr = "" + levelName;

		if (title != null) {
			titleStr += ". " + title;
		}
		return titleStr;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getUserReply() {
		return userReply;
	}

	public void setUserReply(String userReply) {
		this.userReply = userReply;
	}

	public ArrayList<String> getLevelKeys() {
		return levelKeys;
	}

	public void setLevelKeys(ArrayList<String> levelKeys) {
		this.levelKeys = levelKeys;
	}

	public void addLevelKey(String levelKey) {
		if (this.levelKeys == null) {
			this.levelKeys = new ArrayList<String>();
		}
		this.levelKeys.add(levelKey);
	}

	public String getAnswerTime() {
		return answerTime;
	}

	public void setAnswerTime(String answerTime) {
		this.answerTime = answerTime;
	}

	public void setAnswerTime(Date date) {
		SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");

		this.answerTime = format.format(date);
	}

	public ArrayList<String> getAnswers() {
		return answers;
	}

	public void setAnswers(ArrayList<String> answers) {
		this.answers = answers;
	}

	public Double getLng() {
		return lng;
	}

	public void setLng(Double lng) {
		this.lng = lng;
	}

	public Double getLat() {
		return lat;
	}

	public void setLat(Double lat) {
		this.lat = lat;
	}

}
